#! /bin/bash

DATAX_HOME=/opt/module/datax

#DataX导出路径不允许存在空文件，该函数作用为清理空文件
handle_export_path(){
  for i in `hadoop fs -ls -R $1 | awk '{print $8}'`; do
    hadoop fs -test -z $i
    if [[ $? -eq 0 ]]; then
      echo "$i文件大小为0，正在删除"
      hadoop fs -rm -r -f $i
    fi
  done
}

#数据导出
export_data() {
  datax_config=$1
  export_dir=$2
  handle_export_path $export_dir
  $DATAX_HOME/bin/datax.py -p"-Dexportdir=$export_dir" $datax_config
}

case $1 in
  "ads_age_order_user_count")
    export_data /opt/module/datax/job/export/edu_report.ads_age_order_user_count.json /warehouse/edu/ads/ads_age_order_user_count
  ;;
  "ads_category_course_trade_count")
    export_data /opt/module/datax/job/export/edu_report.ads_category_course_trade_count.json /warehouse/edu/ads/ads_category_course_trade_count
  ;;
  "ads_category_firstplay_retention_count")
    export_data /opt/module/datax/job/export/edu_report.ads_category_firstplay_retention_count.json /warehouse/edu/ads/ads_category_firstplay_retention_count
  ;;
  "ads_chapter_video_play_count")
    export_data /opt/module/datax/job/export/edu_report.ads_chapter_video_play_count.json /warehouse/edu/ads/ads_chapter_video_play_count
  ;;
  "ads_cource_end_combined")
    export_data /opt/module/datax/job/export/edu_report.ads_cource_end_combined.json /warehouse/edu/ads/ads_cource_end_combined
  ;;
  "ads_cource_end_user_count")
    export_data /opt/module/datax/job/export/edu_report.ads_cource_end_user_count.json /warehouse/edu/ads/ads_cource_end_user_count
  ;;
  "ads_cource_user_avg_end_chapter_video_count")
    export_data /opt/module/datax/job/export/edu_report.ads_cource_user_avg_end_chapter_video_count.json /warehouse/edu/ads/ads_cource_user_avg_end_chapter_video_count
  ;;
  "ads_cource_video_play_count")
    export_data /opt/module/datax/job/export/edu_report.ads_cource_video_play_count.json /warehouse/edu/ads/ads_cource_video_play_count
  ;;
  "ads_course_comment_count")
    export_data /opt/module/datax/job/export/edu_report.ads_course_comment_count.json /warehouse/edu/ads/ads_course_comment_count
  ;;
  "ads_course_exam_count")
    export_data /opt/module/datax/job/export/edu_report.ads_course_exam_count.json /warehouse/edu/ads/ads_course_exam_count
  ;;
  "ads_course_firstplay_retention_count")
    export_data /opt/module/datax/job/export/edu_report.ads_course_firstplay_retention_count.json /warehouse/edu/ads/ads_course_firstplay_retention_count
  ;;
  "ads_course_trade_count")
    export_data /opt/module/datax/job/export/edu_report.ads_course_trade_count.json /warehouse/edu/ads/ads_course_trade_count
  ;;
  "ads_exampaper_combined_count")
    export_data /opt/module/datax/job/export/edu_report.ads_exampaper_combined_count.json /warehouse/edu/ads/ads_exampaper_combined_count
  ;;
  "ads_exampaper_score_count")
    export_data /opt/module/datax/job/export/edu_report.ads_exampaper_score_count.json /warehouse/edu/ads/ads_exampaper_score_count
  ;;
  "ads_new_order_user_stats")
    export_data /opt/module/datax/job/export/edu_report.ads_new_order_user_stats.json /warehouse/edu/ads/ads_new_order_user_stats
  ;;
  "ads_page_path")
    export_data /opt/module/datax/job/export/edu_report.ads_page_path.json /warehouse/edu/ads/ads_page_path
  ;;
  "ads_province_trade_count")
    export_data /opt/module/datax/job/export/edu_report.ads_province_trade_count.json /warehouse/edu/ads/ads_province_trade_count
  ;;
  "ads_question_right_rate")
    export_data /opt/module/datax/job/export/edu_report.ads_question_right_rate.json /warehouse/edu/ads/ads_question_right_rate
  ;;
  "ads_sourse_order")
    export_data /opt/module/datax/job/export/edu_report.ads_sourse_order.json /warehouse/edu/ads/ads_sourse_order
  ;;
  "ads_subject_firstplay_retention_count")
    export_data /opt/module/datax/job/export/edu_report.ads_subject_firstplay_retention_count.json /warehouse/edu/ads/ads_subject_firstplay_retention_count
  ;;
  "ads_subjet_course_trade_count")
    export_data /opt/module/datax/job/export/edu_report.ads_subjet_course_trade_count.json /warehouse/edu/ads/ads_subjet_course_trade_count
  ;;
  "ads_trade_combined_count")
    export_data /opt/module/datax/job/export/edu_report.ads_trade_combined_count.json /warehouse/edu/ads/ads_trade_combined_count
  ;;
  "ads_traffic_stats_by_source")
    export_data /opt/module/datax/job/export/edu_report.ads_traffic_stats_by_source.json /warehouse/edu/ads/ads_traffic_stats_by_source
  ;;
  "ads_user_action")
    export_data /opt/module/datax/job/export/edu_report.ads_user_action.json /warehouse/edu/ads/ads_user_action
  ;;
  "ads_user_change")
    export_data /opt/module/datax/job/export/edu_report.ads_user_change.json /warehouse/edu/ads/ads_user_change
  ;;
  "ads_user_retention")
    export_data /opt/module/datax/job/export/edu_report.ads_user_retention.json /warehouse/edu/ads/ads_user_retention
  ;;
  "ads_user_stats")
    export_data /opt/module/datax/job/export/edu_report.ads_user_stats.json /warehouse/edu/ads/ads_user_stats
  ;;
  "all")
    export_data /opt/module/datax/job/export/edu_report.ads_age_order_user_count.json /warehouse/edu/ads/ads_age_order_user_count
    export_data /opt/module/datax/job/export/edu_report.ads_category_course_trade_count.json /warehouse/edu/ads/ads_category_course_trade_count
    export_data /opt/module/datax/job/export/edu_report.ads_category_firstplay_retention_count.json /warehouse/edu/ads/ads_category_firstplay_retention_count
    export_data /opt/module/datax/job/export/edu_report.ads_chapter_video_play_count.json /warehouse/edu/ads/ads_chapter_video_play_count
    export_data /opt/module/datax/job/export/edu_report.ads_cource_end_combined.json /warehouse/edu/ads/ads_cource_end_combined
    export_data /opt/module/datax/job/export/edu_report.ads_cource_end_user_count.json /warehouse/edu/ads/ads_cource_end_user_count
    export_data /opt/module/datax/job/export/edu_report.ads_cource_user_avg_end_chapter_video_count.json /warehouse/edu/ads/ads_cource_user_avg_end_chapter_video_count
    export_data /opt/module/datax/job/export/edu_report.ads_cource_video_play_count.json /warehouse/edu/ads/ads_cource_video_play_count
    export_data /opt/module/datax/job/export/edu_report.ads_course_comment_count.json /warehouse/edu/ads/ads_course_comment_count
    export_data /opt/module/datax/job/export/edu_report.ads_course_exam_count.json /warehouse/edu/ads/ads_course_exam_count
    export_data /opt/module/datax/job/export/edu_report.ads_course_firstplay_retention_count.json /warehouse/edu/ads/ads_course_firstplay_retention_count
    export_data /opt/module/datax/job/export/edu_report.ads_course_trade_count.json /warehouse/edu/ads/ads_course_trade_count
    export_data /opt/module/datax/job/export/edu_report.ads_exampaper_combined_count.json /warehouse/edu/ads/ads_exampaper_combined_count
    export_data /opt/module/datax/job/export/edu_report.ads_exampaper_score_count.json /warehouse/edu/ads/ads_exampaper_score_count
    export_data /opt/module/datax/job/export/edu_report.ads_new_order_user_stats.json /warehouse/edu/ads/ads_new_order_user_stats
    export_data /opt/module/datax/job/export/edu_report.ads_page_path.json /warehouse/edu/ads/ads_page_path
    export_data /opt/module/datax/job/export/edu_report.ads_province_trade_count.json /warehouse/edu/ads/ads_province_trade_count
    export_data /opt/module/datax/job/export/edu_report.ads_question_right_rate.json /warehouse/edu/ads/ads_question_right_rate
    export_data /opt/module/datax/job/export/edu_report.ads_sourse_order.json /warehouse/edu/ads/ads_sourse_order
    export_data /opt/module/datax/job/export/edu_report.ads_subject_firstplay_retention_count.json /warehouse/edu/ads/ads_subject_firstplay_retention_count
    export_data /opt/module/datax/job/export/edu_report.ads_subjet_course_trade_count.json /warehouse/edu/ads/ads_subjet_course_trade_count
    export_data /opt/module/datax/job/export/edu_report.ads_trade_combined_count.json /warehouse/edu/ads/ads_trade_combined_count
    export_data /opt/module/datax/job/export/edu_report.ads_traffic_stats_by_source.json /warehouse/edu/ads/ads_traffic_stats_by_source
    export_data /opt/module/datax/job/export/edu_report.ads_user_action.json /warehouse/edu/ads/ads_user_action
    export_data /opt/module/datax/job/export/edu_report.ads_user_change.json /warehouse/edu/ads/ads_user_change
    export_data /opt/module/datax/job/export/edu_report.ads_user_retention.json /warehouse/edu/ads/ads_user_retention
    export_data /opt/module/datax/job/export/edu_report.ads_user_stats.json /warehouse/edu/ads/ads_user_stats
  ;;
esac
